/**
 * 
 */
package zzzhc.image.ui;

import java.awt.Component;
import java.awt.Image;
import java.awt.image.BufferedImage;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;

class ImageTableCellRenderer implements TableCellRenderer {

	private int scale = 1;

	public ImageTableCellRenderer() {

	}

	public ImageTableCellRenderer(int scale) {
		this.scale = scale;
	}

	public int getScale() {
		return scale;
	}

	public void setScale(int scale) {
		this.scale = scale;
	}

	public Component getTableCellRendererComponent(JTable table, Object value,
			boolean isSelected, boolean hasFocus, int row, int column) {
		BufferedImage image = (BufferedImage) value;
		Image scaledImage = image.getScaledInstance(image.getWidth()
				* getScale(), image.getHeight() * getScale(),
				Image.SCALE_SMOOTH);
		JLabel label = new JLabel(new ImageIcon(scaledImage));
		return label;
	}
}